<#include "../common/_meta.ftl">

<body>
<article class="page-container">
    <form action="" method="post" class="form form-horizontal" id="form-user-edit">
        <input type="hidden" id="userId" value=${user.userId?c!'null'}>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>userName：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <input type="text" class="input-text" value="${user.userName!'null'}" id="username" name="username">
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>password：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <input type="text" class="input-text" value="${user.password!'null'}" id="password" name="password"
                       title=""/>
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3">phone：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <input type="text" class="input-text" value="${user.phone!'null'}" id="phone" name="phone">
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3">现居地：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <input type="text" class="input-text" value="${user.currentResidence!'null'}" name="currentResidence"
                       id="currentResidence" title="">
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>合租：</label>
            <div class="formControls col-xs-8 col-sm-9 skin-minimal">
                <div class="radio-box">
                    <input name="shared" type="radio" id="shared-1" value="1">
                    <label for="shared-1">愿意</label>
                </div>
                <div class="radio-box">
                    <input name="shared" type="radio" value="0" id="shared-0">
                    <label for="shared-0">不愿意</label>
                </div>
            </div>
        </div>
        <div class="row cl">
            <div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-3">
                <input class="btn btn-primary radius" type="submit" value="&nbsp;&nbsp;提交&nbsp;&nbsp;">
            </div>
        </div>
    </form>
</article>


<#include "../common/_footer.ftl">
<script type="text/javascript"
        src="${request.contextPath}/public/lib/jquery.validation/1.14.0/jquery.validate.js"></script>
<script type="text/javascript"
        src="${request.contextPath}/public/lib/jquery.validation/1.14.0/validate-methods.js"></script>
<script type="text/javascript" src="${request.contextPath}/public/lib/jquery.validation/1.14.0/messages_zh.js"></script>
<script>
    $(function () {
        if (${user.shared}==1
    )
        {
            $("#shared-1").attr("checked", true);
        }
    else
        {
            $("#shared-0").attr("checked", true);
        }
    });


    $("#form-user-edit").validate({
        rules: {
            username: {
                required: true,
                minlength: 2,
                maxlength: 16
            },
            password: {
                required: true,
            },
            phone: {
                required: true,
                isMobile: true,
            }
        },
        onkeyup: false,
        focusCleanup: true,
        success: "valid",
        submitHandler: function (form) {
            //获取表单信息
            var userId = parseInt($("#userId").val());
            var userName = $("#username").val();
            var password = $("#password").val();
            var phone = $("#phone").val();
            var currentResidence = $("#currentResidence").val();
            var shared = $("input[name='shared']:checked").val();
            var jsonData = {
                "userId": userId,
                "userName": userName,
                "password": password,
                "phone": phone,
                "currentResidence": currentResidence,
                "shared": shared
            };
            $.ajax({
                url: "${request.contextPath}/user/updateByAdmin",
                type: "post",
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                data: JSON.stringify(jsonData),
                success: function (res) {
                    if (res.code === 200) {
                        var index = parent.layer.getFrameIndex(window.name);
                        parent.reDrew();
                        parent.layer.close(index);
                    } else {
                        layer.msg(res.msg, {time: 1000});
                    }


                }

            });
        }
    });
</script>
</body>

